package com.xuchao.rabbit.b1;

import com.rabbitmq.client.*;
import com.xuchao.rabbit.utils.RabbitMqUtils;

/**
 * @Author xuchao
 * @Date:2023/6/4 18:05
 * @description 第一个RabbitMQ的demo
 * @Version 1.0
 */
public class Consumer {
    //队列名称
    public static final String QUEUE_NAME="hello";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();

        //声明 接收消息
        DeliverCallback deliverCallback = (consumerTage,message)->{
            System.out.println(new String(message.getBody()));
        };

        //取消消息时的回调
        CancelCallback cancelCallback = consumerTage->{
            System.out.println("消息消费被中断");
        };
        /**
         * 消费者接收消息
         * 1.队列名
         * 2.是否自动应答
         * 3.消费者未成功消费的回调
         * 4.消费者消费被中断的回调
         */
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
    }
}
